package com.fang.networkdisk.controller;

import com.fang.common.common.CommonPage;
import com.fang.common.common.CommonResult;
import com.fang.common.request.BaseController;
import com.fang.common.util.CommonResultUtil;
import com.fang.networkdisk.entity.bo.ReqPathPermitRelationBo;
import com.fang.networkdisk.entity.dto.ReqPathPermitRelationDto;
import com.fang.networkdisk.entity.vo.ReqPathPermitRelationVo;
import com.fang.networkdisk.service.TbNetDisReqPathPermitRelationService;
import com.fang.networkdisk.util.NDBeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Bernie_fang
 * @Description:
 * @create 2025/2/2 23:44
 **/
@RestController
@RequestMapping("/system/reqPathPermitRelation")
public class ReqPathPermitRelationController extends BaseController {

    @Resource
    private TbNetDisReqPathPermitRelationService tbNetDisReqPathPermitRelationService;

    @PostMapping("/list")
    public CommonResult<CommonPage<List<ReqPathPermitRelationVo>>> queryReqPathPermitRelation(@RequestBody ReqPathPermitRelationDto reqPathPermitRelationDto) {
        ReqPathPermitRelationBo ReqPathPermitRelationBo = new ReqPathPermitRelationBo();
        NDBeanUtils.copyListProperties(reqPathPermitRelationDto, ReqPathPermitRelationBo);
        CommonPage result = tbNetDisReqPathPermitRelationService.queryReqPathPermitRelation(ReqPathPermitRelationBo);
        return CommonResultUtil.success(result);
    }

    @PostMapping("/add")
    public CommonResult<CommonPage<List<ReqPathPermitRelationVo>>> addReqPathPermitRelation(@RequestBody ReqPathPermitRelationDto reqPathPermitRelationDto) {
        String authorId = super.getAuthorId();
        ReqPathPermitRelationBo reqPathPermitRelationBo = new ReqPathPermitRelationBo();
        NDBeanUtils.copyListProperties(reqPathPermitRelationDto, reqPathPermitRelationBo);
        reqPathPermitRelationBo.setCreateUser(authorId);
        reqPathPermitRelationBo.setUpdateUser(authorId);
        tbNetDisReqPathPermitRelationService.addReqPathPermitRelation(reqPathPermitRelationBo);
        return CommonResultUtil.success();
    }

    @PostMapping("/update")
    public CommonResult<CommonPage<List<ReqPathPermitRelationVo>>> updateReqPathPermitRelation(@RequestBody ReqPathPermitRelationDto reqPathPermitRelationDto) {
        String authorId = super.getAuthorId();
        ReqPathPermitRelationBo reqPathPermitRelationBo = new ReqPathPermitRelationBo();
        NDBeanUtils.copyListProperties(reqPathPermitRelationDto, reqPathPermitRelationBo);
        reqPathPermitRelationBo.setCreateUser(null);
        reqPathPermitRelationBo.setUpdateUser(authorId);
        tbNetDisReqPathPermitRelationService.updateReqPathPermitRelationById(reqPathPermitRelationBo);
        return CommonResultUtil.success();
    }

    @GetMapping("/delete/{id}")
    public CommonResult<CommonPage<List<ReqPathPermitRelationVo>>> deleteReqPathPermitRelation(@PathVariable("id") Integer id) {
        String authorId = super.getAuthorId();
        tbNetDisReqPathPermitRelationService.deleteReqPathPermitRelationById(id, authorId);
        return CommonResultUtil.success();
    }

}
